﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class house : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        initPage();
    }
    protected void initPage() {
        try
        {
            int catid = Convert.ToInt32(Request.QueryString["catid"]);
            int houseid = Convert.ToInt32(Request.QueryString["houseid"]);
            string query = "SELECT * FROM mwc_house WHERE catid = " + catid.ToString() + " AND id = " + houseid.ToString();
            SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["mwc_con"]);
            sc.Open();
            SqlCommand scmd = new SqlCommand(query,sc);
            SqlDataReader sdr = scmd.ExecuteReader();
            while (sdr.Read()) { 
                //house_title.Text = sdr[""]
                house_title.Text = getNameCategory(catid.ToString());
                house_fulltext.Text = sdr["fulltext"].ToString();
                house_saganr.Text = sdr["saganr"].ToString();
                house_area.Text = sdr["area"].ToString();
                house_leje.Text = sdr["rent_per_m2"].ToString();
                //house_leje.Text = sdr[""]
                house_address.Text = sdr["address"].ToString();
                house_address_1.Text = sdr["address"].ToString();
            }
        }
        catch (Exception e) {
            Response.Redirect("~/Default.aspx");
        }
    }
    protected string getNameCategory(string id) {
        string catName = "";
        SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["mwc_con"]);
        sc.Open();
        string query = "SELECT * FROM mwc_housecategory WHERE id = " + id ;
        SqlCommand scmd = new SqlCommand(query,sc);
        SqlDataReader sdr = scmd.ExecuteReader();
        while (sdr.Read()) {
            catName = sdr["catname"].ToString();
        }
        return catName;
    }
}

